//
//  DDBossCeoService.m
//  DingDongZP
//
//  Created by weily on 16/5/25.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDCompanyHomeService.h"

@implementation DDCompanyHomeService


- (void)uploadCeoAvatar:(UIImage *)img
               callback:(EditBlock)callback {
	
    
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"employer_cel_logo"];
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    [manager UPLOAD:URLString parameters:nil filesDatas:@{@"file": img} success:^(id responseObject) {
        callback([responseObject[@"code"] boolValue]);
    } failure:^(id responseObject, NSError *error) {
        callback(NO);
    }];
}

- (void)uploadCompanyLogo:(UIImage *)img
                 callback:(EditBlock)callback {
	
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"employer_company_logo"];
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    [manager UPLOAD:URLString parameters:nil filesDatas:@{@"file": img} success:^(id responseObject) {
        callback([responseObject[@"code"] boolValue]);
    } failure:^(id responseObject, NSError *error) {
        callback(NO);
    }];
}

- (void)uploadProductLogo:(UIImage *)img
                 callback:(EditBlock)callback {
	
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"employer_product_logo"];
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    [manager UPLOAD:URLString parameters:nil filesDatas:@{@"file": img} success:^(id responseObject) {
        callback([responseObject[@"code"] boolValue]);
    } failure:^(id responseObject, NSError *error) {
        callback(NO);
    }];
}

- (void)uploadCompanyShow:(UIImage *)img
                 callback:(EditBlock)callback {
	
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"employer_company_show"];
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    [manager UPLOAD:URLString parameters:nil filesDatas:@{@"file": img} success:^(id responseObject) {
        callback([responseObject[@"code"] boolValue]);
    } failure:^(id responseObject, NSError *error) {
        callback(NO);
    }];
}

- (void)setCEOInfo:(DDBossCEOInfo *)info
          callback:(void (^)(BOOL succ, NSString *err))callback {
	
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"employer_set_ceo"];
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:[info getParams] success:^(id responseObject) {
//        NSLog(@"修改个人信息返回数据:%@", responseObject);
        callback([responseObject[@"code"] boolValue], responseObject[@"msg"]);
    } failure:^(id responseObject, NSError *error) {
        callback(NO, error.domain);
    }];
}

- (void)setProductInfo:(DDProductSetInfo *)info
              cakkback:(void (^)(BOOL succ, NSString *err))callback {
	
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"employer_set_product_info"];
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    NSDictionary *params = [info yy_modelToJSONObject];
    
    [manager POST:URLString parameters:params success:^(id responseObject) {
//        NSLog(@"修改个人信息返回数据:%@", responseObject);
        callback([responseObject[@"code"] boolValue], responseObject[@"msg"]);
    } failure:^(id responseObject, NSError *error) {
        callback(NO, error.domain);
    }];
}

- (void)queryCompanyInfo:(completeBlock)callback {
	
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"employer_query_companyinfo"];
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:nil success:^(id responseObject) {
        
        NSInteger code = [responseObject[@"code"] integerValue];
        if (code == 1) {
            NSDictionary *data = responseObject[@"data"];
            DDCompanyInfo *info = [DDCompanyInfo yy_modelWithDictionary:data];
            callback(info, nil);
        }
        else {
            callback(nil, nil);
        }
    } failure:^(id responseObject, NSError *error) {
        callback(nil, error);
    }];
}

- (void)deleteCompanyImage:(NSString *)showid callback:(EditBlock)block {
	
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"employer_delete_companyshow"];
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:@{@"show_id": showid} success:^(id responseObject) {
//        NSLog(@"修改个人信息返回数据:%@", responseObject);
        block([responseObject[@"code"] boolValue]);
    } failure:^(id responseObject, NSError *error) {
        block(NO);
    }];
}



@end

@implementation DDBossCEOInfo

+ (instancetype)withN:(NSString *)name p:(NSString *)positionid pna:(NSString *)positionname in:(NSString *)intro
{
    DDBossCEOInfo *info = [[self alloc] init];
    info.name = name;
    info.positionId = positionid;
    info.positionCustomName = positionname;
    info.intro = intro;
    return info;
}

- (NSDictionary *)getParams {
    NSMutableDictionary *paras = [NSMutableDictionary new];
    if (self.name) {
        paras[@"ceo_name"] = self.name;
    }
    if (self.positionId) {
        paras[@"ceo_position_id"] = self.positionId;
    }
    if (self.positionCustomName) {
        paras[@"ceo_position_customized"] = self.positionCustomName;
    }
    if (self.intro) {
        paras[@"ceo_intro"] = self.intro;
    }
    return paras;
}

@end

@implementation DDProductSetInfo



@end
